package com.centling.smartSealForPhone.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.IntDef;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.centling.smartSealForPhone.R;
import com.centling.smartSealForPhone.widget.TitleBar;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * @author fionera
 */
@SuppressLint("Registered")
public class TitleBarActivity
        extends BaseActivity {
    @IntDef({View.VISIBLE, View.INVISIBLE, View.GONE})
    @Retention(RetentionPolicy.SOURCE)
    @interface Visibility {
    }

    private View mLayoutMain;
    public TitleBar mTitleBar;
    private LinearLayout mLayoutContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mLayoutMain = View.inflate(mContext, R.layout.title_bar_content, null);
        mLayoutContent = findViewById(R.id.title_bar_content);
        mTitleBar = findViewById(R.id.title_bar);
        mTitleBar.setLeftDrawable(R.drawable.ic_action_back);
        mTitleBar.setTitleBarLeftClick(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    public <T extends View> T findViewById(int id) {
        T view = mLayoutMain.findViewById(id);
        if (view == null) {
            return super.findViewById(id);
        }
        return view;
    }

    @Override
    public void setContentView(int layoutResID) {
        View mContent = getLayoutInflater().inflate(layoutResID, null);
        mLayoutContent.addView(mContent, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        super.setContentView(mLayoutMain);
    }

    public ImageView getRightImageView() {
        return mTitleBar.getIvRight();
    }

    public void setTitleBarText(String title) {
        mTitleBar.setTitleBarText(title);
    }

    public void setTitleBarColor(int color) {
        mTitleBar.setTitleBarColor(ContextCompat.getColor(mContext, color));
    }

    public void setTitleBarLeft(int drawable) {
        mTitleBar.setLeftDrawable(drawable);
    }

    public void setTitleBarRight(int drawable) {
        mTitleBar.setRightDrawable(drawable);
    }

    public void setTitleBarRightPadding(int drawable) {
        mTitleBar.setRightDrawablePadding(drawable);
    }

    public void setTitleBarLeft(String leftText) {
        mTitleBar.setLeftText(leftText);
    }

    public void setTitleBarRight(String rightText) {
        mTitleBar.setRightText(rightText);
    }

    public void setTitleBarRight(String rightText, int iconId, boolean iconAtLeft) {
        mTitleBar.setRightTextAndIcon(rightText, iconId, iconAtLeft);
    }

    public void setTitleBarLeft(String leftText, int iconId, boolean iconAtLeft) {
        mTitleBar.setLeftTextAndIcon(leftText, iconId, iconAtLeft);
    }

    public void setTitleBarLeftVisibility(@Visibility int visibility) {
        mTitleBar.setLeftVisibility(visibility);
    }

    public void setTitleBarRightVisibility(@Visibility int visibility) {
        mTitleBar.setRightVisibility(visibility);
    }

    public void setTitleBarVisibility(@Visibility int visibility) {
        mTitleBar.setVisibility(visibility);
    }

    public void setTitleBarLeftClick(View.OnClickListener onLeftClickListener) {
        mTitleBar.setTitleBarLeftClick(onLeftClickListener);
    }

    public void setTitleBarRightClick(View.OnClickListener onRightClickListener) {
        mTitleBar.setTitleBarRightClick(onRightClickListener);
    }

    public void setTitleBarTitleClick(View.OnClickListener onTitleClickListener) {
        mTitleBar.setTitleBarTitleClick(onTitleClickListener);
    }

    public TitleBar getTitleBar() {
        return mTitleBar;
    }

    public void setTitleBarRightFirstClick(View.OnClickListener onRightClickListener) {
        mTitleBar.setTitleBarRightFirstClick(onRightClickListener);
    }

    public void setTitleBarRightFirstVisibility(@Visibility int visibility) {
        mTitleBar.setRightFirstVisibility(visibility);
    }

    public void setTitleBarRightFirst(int drawable) {
        mTitleBar.setRightFirstDrawable(drawable);
    }
}
